package cn.imokay.classLoad;

public class DeadThreadTest {
    public static void main(String[] args) {
        Runnable r = () ->{
            System.out.println(Thread.currentThread().getName()+"开始");
            DeadThread deadthread = new DeadThread();
            System.out.println(Thread.currentThread().getName()+"结束");
        };

        Thread t1 = new Thread(r, "线程1");
        Thread t2 = new Thread(r, "线程2");
        t1.start();
        t2.start();
        /*类只会加载一次,只有一个线程会出发类的一次加载,static代码块只会执行1次,并且睡眠结束前另一个线程一致在等待:
        线程1开始
        线程2开始
        线程1初始化当前类
        线程2结束
        线程1结束*/
    }
}
class DeadThread {
    static {
        System.out.println(Thread.currentThread().getName() + "初始化当前类");
        try {
            Thread.sleep(100000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
